package com.yykj.base.server.service.impl;

import com.yykj.base.server.dto.AppInfoDTO;
import com.yykj.base.server.model.entity.AppInfo;
import com.yykj.base.server.model.repository.AppInfoRepository;
import com.yykj.base.server.service.AppInfoService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AppInfoServiceImpl implements AppInfoService {
    @Override
    public AppInfoDTO getAppInfo() {
        AppInfo info = appInfoRepository.findFirstBy();
        if(info == null){
            info = new AppInfo();
            info.setCheckStatus(Boolean.FALSE);
            info = appInfoRepository.save(info);
        }
        AppInfoDTO ret = new AppInfoDTO();
        BeanUtils.copyProperties(info,ret);
        return ret;
    }

    private AppInfoRepository appInfoRepository;

    @Autowired
    public void setAppInfoRepository(AppInfoRepository appInfoRepository) {
        this.appInfoRepository = appInfoRepository;
    }
}
